#ifndef __LLCC68_DRIVE_H
#define __LLCC68_DRIVE_H

#include "at32f435_437.h"
#include "at32f435_437_board.h"

#include "llcc68.h"

#include "FreeRTOS.h"
#include "task.h"
#include "event_groups.h"

#define LORA_FRE										434610000
#define LORA_TX_OUTPUT_POWER				22
#define LORA_BANDWIDTH							(LLCC68_LORA_BW_250)
#define LORA_SPREADING_FACTOR				(LLCC68_LORA_SF9)
#define LORA_CODINGRATE							(LLCC68_LORA_CR_4_8)
#define LORA_PREAMBLE_LENGTH				8
#define LORA_LLCC68_SYMBOL_TIMEOUT	0
#define LORA_FIX_LENGTH_PAYLOAD_ON	(LLCC68_LORA_PKT_EXPLICIT)
#define LORA_IQ_INVERSION_ON				false
#define LORA_RX_TIMEOUT_VALUE				5000
#define LORA_RX_CONTINUOUS					1
#define LORA_SYMB_TIMEOUT						3000

#define SPI1_CS_HIGH()			gpio_bits_set(GPIOA, GPIO_PINS_15)
#define SPI1_CS_LOW()				gpio_bits_reset(GPIOA, GPIO_PINS_15)

#define LLCC68_RST_HIGH()		gpio_bits_set(GPIOA, GPIO_PINS_1)
#define LLCC68_RST_LOW()		gpio_bits_set(GPIOA, GPIO_PINS_1)

#define LLCC68_BUSY_READ()	gpio_input_data_bit_read(GPIOC, GPIO_PINS_2)

#define DIO_DONE_BIT	( 1 << 0 )

#define IRQ_TX_DONE_BIT ( 1 << 0 )
#define IRQ_RX_DONE_BIT ( 1 << 1 )
#define IRQ_PREAMBLE_DETECTED_BIT ( 1 << 2 )
#define IRQ_SYNC_WORD_VALID_BIT ( 1 << 3 )
#define IRQ_HEADER_VALID_BIT ( 1 << 4 )
#define IRQ_HEADER_ERR_BIT ( 1 << 5 )
#define IRQ_CRC_ERR_BIT	( 1 << 6 )
#define IRQ_CAD_DONE_BIT ( 1 << 7 )
#define IRQ_CAD_DETECTED_BIT ( 1 << 8 )
#define IRQ_TIMEOUT_BIT ( 1 << 9 )

void llcc68_rx(void);
void llcc68_send(uint8_t *buffer, uint8_t size);
void llcc68_set_tx_cfg(uint8_t pld_len_in_bytes);
void llcc68_chip_init(void);
void llcc68_spi_init(void);
void llcc68_gpio_init(void);

#endif // __LLCC68_DRIVE_H_